package org.example.wc

import org.apache.spark.sql.{DataFrame, SparkSession}

import java.util.Properties

object ConnectMysql {

  val CONN_PROP_MYSQL = new Properties()
  //  CONN_PROP_SEA.setProperty("driver", "com.mysql.jdbc.Driver")
  CONN_PROP_MYSQL.setProperty("url", "jdbc:mysql://localhost:3306/spark_mysql")
  CONN_PROP_MYSQL.setProperty("user", "root")
  CONN_PROP_MYSQL.setProperty("password", "root")

  def main(args: Array[String]): Unit = {

      var session:SparkSession =SparkSession.
        builder()
        .master("local[*]")
        .appName("cmq")
        .enableHiveSupport()
        .getOrCreate()

    val dataFrame: DataFrame = session.read.jdbc(
      CONN_PROP_MYSQL.getProperty("url"),
      "(select * from student) aa",
      CONN_PROP_MYSQL
    )

    dataFrame.show()
    dataFrame.collect()

  }

}
